﻿using System;
using System.Collections.Generic;
using System.Linq;
using Pay.Core;
using Pay.Data;
using Pay.DTO;
using Pay.IService;
using Pay.Service.Cache;
using Pay.TO;

namespace Pay.Service.Service {
	public class BankNumberService : ServiceBase, IBankNumberService, IDisposable {
		private IUnitOfWork _iUnitOfWork;

		public BankNumberService(IUnitOfWork iUnitOfWork) : base(iUnitOfWork) {
			_iUnitOfWork = iUnitOfWork;
		}

		public PagedResult<bank_number_dto> Get(BranchQuery branchQuery) {
			var filter = PredicateBuilder.True<BankNumber>();
			if (!string.IsNullOrEmpty(branchQuery.name))
				filter = filter.And(c => c.BranchName.Contains(branchQuery.name));
			if (branchQuery.province_id > 0)
				filter = filter.And(c => c.Provinceid == branchQuery.province_id);
			if (branchQuery.city_id > 0)
				filter = filter.And(c => c.CityId == branchQuery.city_id);
			if (!string.IsNullOrEmpty(branchQuery.bank_code))
				filter = filter.And(c => c.BankCode == branchQuery.bank_code);

			return context.BankNumbers.FromCachePaged<BankNumber, bank_number_dto>(branchQuery.page, branchQuery.size, filter, orderBy => orderBy.OrderByDescending(c => c.Id));
		}
	}
}
